package com.chixing.day13.day13_Home;

import java.util.*;

public class ProductSTest {
    public static void main(String[] args){
        List<ProductS> list = new ArrayList<>();
        ProductS p1 = new ProductS("宝洁","洗手粉",18.5);
        ProductS p2 = new ProductS("联合利华","肥皂",4.5);
        ProductS p3 = new ProductS("宝洁","牙膏",32.5);
        ProductS p4 = new ProductS("宝洁","毛巾",14.5);
        ProductS p5 = new ProductS("洁利","洗面奶",26.0);
        ProductS p6 = new ProductS("好迪","洗发水",27.5);
        ProductS p7 = new ProductS("多芬","沐浴露",38.5);
        ProductS p8 = new ProductS("宝洁","洗洁精",3.4);
        list.add(p1);
        list.add(p2);
        list.add(p3);
        list.add(p4);
        list.add(p5);
        list.add(p6);
        list.add(p7);
        list.add(p8);
        Map<String,Double> map = new HashMap<>();
        for (ProductS p : list) {
            if(map.containsKey(p.getBrand())){
                map.put(p.getBrand(),map.get(p.getBrand()) + p.getCost());
            }else{
                map.put(p.getBrand(),p.getCost());
            }
        }
        Set<String> set = map.keySet();
        for (String str: set) {
            System.out.println( str + " - " + map.get(str));
        }



    }
}
